package com.lry.jvm.instructions.stack;


import com.lry.jvm.instructions.base.NoOperandsInstruction;
import com.lry.jvm.rtda.Frame;
import com.lry.jvm.rtda.OperandStack;
import com.lry.jvm.rtda.Slot;
//dup 复制栈顶部一个字长内容
public class dup extends NoOperandsInstruction {
    @Override
    public byte getOpCode() {
        return 0x59;
    }

    @Override
    public void execute(Frame frame) throws Exception {
        OperandStack operandStack = frame.getOperandStack();
        Slot slot = operandStack.popSlot();
        //pop一次，push两次，相当于push一次
        operandStack.pushSlot(slot);
        operandStack.pushSlot(slot);
    }
}
